Attribute VB_Name = "modWindowStyle"
Option Explicit

'Useage:
'Private Sub chkControlBox_Click()
'    ControlBoxStyle Me.hwnd, (chkControlBox.Value = vbChecked)
'End Sub
'
'Private Sub chkMaxButton_Click()
'    MaxButtonStyle Me.hwnd, (chkMaxButton.Value = vbChecked)
'End Sub
'
'Private Sub chkMinButton_Click()
'    MinButtonStyle Me.hwnd, (chkMinButton.Value = vbChecked)
'End Sub
'
'Private Sub chkSizeableBorder_Click()
'    SizeableBorderStyle Me.hwnd, (chkSizeableBorder.Value = vbChecked)
'End Sub
'
'Private Sub chkTaskBar_Click()
'    TaskBarStyle Me.hwnd, (chkTaskBar.Value = vbChecked)
'End Sub
'
'Private Sub chkTitleBar_Click()
'    TitleBarStyle Me.hwnd, (chkTitleBar.Value = vbChecked)
'End Sub
'
'Private Sub chkToolWindow_Click()
'    ToolWindowStyle Me.hwnd, (chkToolWindow.Value = vbChecked)
'End Sub

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal Form_hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Form_hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const GWL_EXSTYLE = (-20)
Private Const WS_CAPTION = &HC00000     ' WS_BORDER Or WS_DLGFRAME
Private Const WS_EX_APPWINDOW = &H40000
Private Const WS_EX_TOOLWINDOW = &H80&
Private Const WS_SYSMENU = &H80000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_THICKFRAME = &H40000

Private Declare Function SetWindowPos Lib "user32" (ByVal Form_hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H4

' ShowWindow
Private Declare Function ShowWindow Lib "user32" (ByVal Form_hWnd As Long, ByVal nCmdShow As Long) As Long
                 
' ShowWindow Selectors
Const SW_HIDE = 0
Const SW_SHOW = 5
' Set or clear a style or extended style value.
Public Sub SetWindowStyle(ByVal Form_hWnd As Long, ByVal extended_style As Boolean, ByVal style_value As Long, ByVal new_value As Boolean, ByVal brefresh As Boolean)
    Dim style_type As Long
    Dim style As Long
   
    If extended_style Then
        style_type = GWL_EXSTYLE
    Else
        style_type = GWL_STYLE
    End If
    style = GetWindowLong(Form_hWnd, style_type)         ' Get the current style.
    If new_value Then                               ' Add or remove the indicated value.
        style = style Or style_value
    Else
        style = style And Not style_value
    End If

    ' Hide Window if Changing ShowInTaskBar
    If brefresh Then
        ShowWindow Form_hWnd, SW_HIDE
    End If

    ' Set the style.
    SetWindowLong Form_hWnd, style_type, style

    ' Show Window if Changing ShowInTaskBar
    If brefresh Then
        ShowWindow Form_hWnd, SW_SHOW
    End If

    ' Make the window .
    SetWindowPos Form_hWnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER  'redraw window
End Sub

Public Sub PlainDialog(Form_hWnd As Long)
    ControlBoxStyle Form_hWnd, False
    MaxButtonStyle Form_hWnd, False
    MinButtonStyle Form_hWnd, False
    SizeableBorderStyle Form_hWnd, False
    TaskBarStyle Form_hWnd, False
    TitleBarStyle Form_hWnd, False
    ToolWindowStyle Form_hWnd, False
End Sub

Public Sub UtilDialog(Form_hWnd As Long)
    ControlBoxStyle Form_hWnd, True
    MaxButtonStyle Form_hWnd, False
    MinButtonStyle Form_hWnd, False
    SizeableBorderStyle Form_hWnd, False
    TaskBarStyle Form_hWnd, True
    TitleBarStyle Form_hWnd, True
    ToolWindowStyle Form_hWnd, False
End Sub

Public Sub ControlBoxStyle(Form_hWnd As Long, Optional bSet As Boolean = True)
    SetWindowStyle Form_hWnd, False, WS_SYSMENU, bSet, False
End Sub

Public Sub MaxButtonStyle(Form_hWnd As Long, Optional bSet As Boolean = True)
    SetWindowStyle Form_hWnd, False, WS_MAXIMIZEBOX, bSet, False
End Sub

Public Sub MinButtonStyle(Form_hWnd As Long, Optional bSet As Boolean = True)
    SetWindowStyle Form_hWnd, False, WS_MINIMIZEBOX, bSet, False
End Sub

Public Sub SizeableBorderStyle(Form_hWnd As Long, Optional bSet As Boolean = True)
    SetWindowStyle Form_hWnd, False, WS_THICKFRAME, bSet, False
End Sub

Public Sub TaskBarStyle(Form_hWnd As Long, Optional bSet As Boolean = True)
    SetWindowStyle Form_hWnd, True, WS_EX_APPWINDOW, bSet, True
End Sub

Public Sub TitleBarStyle(Form_hWnd As Long, Optional bSet As Boolean = True)
    SetWindowStyle Form_hWnd, False, WS_CAPTION, bSet, False
End Sub

Public Sub ToolWindowStyle(Form_hWnd As Long, Optional bSet As Boolean = True)
    SetWindowStyle Form_hWnd, True, WS_EX_TOOLWINDOW, bSet, False
End Sub
